Conversation
662dfea to
56babbc
Compare
|
Sorry fucked up the squash give me sec |
56babbc to
4e83bfa
Compare
|
Is this ready now @pablogsal? |
|
Here's a somewhat surprising change in behaviour: given these two modules: A.py: B.py: Before this PR the use of With this PR, it reports the lazy import in B.py: Swapping the order of the lazy imports used to not have an effect on the traceback, but now it does: the last lazy import wins. I'm not sure if that's fixable, but I think if we need a single location the first lazy import would be a better winner. |
Okay I think I see why we can't do that, either. I think this is fixable later (perhaps by merging lazy objects, storing all the locations and selecting an appropriate one when printing the traceback). Still, it's a little annoying that this used to work as users would expect. |
|
I think there's a similar issue with modules defining |
| _PyLazyImport_IsActive(PyObject *declaration) | ||
| { | ||
| return FT_ATOMIC_LOAD_INT_RELAXED( | ||
| ((PyLazyImportObject *)declaration)->lz_active); |
There was a problem hiding this comment.
| ((PyLazyImportObject *)declaration)->lz_active); | |
| PyLazyImportObject_CAST(declaration)->lz_active); |
| int | ||
| _PyLazyImport_IsActive(PyObject *declaration) | ||
| { | ||
| return FT_ATOMIC_LOAD_INT_RELAXED( |
There was a problem hiding this comment.
This could probably do with an assert.
| return FT_ATOMIC_LOAD_INT_RELAXED( | |
| assert(PyLazyImport_CheckExact(declaration)); | |
| return FT_ATOMIC_LOAD_INT_RELAXED( |
Yhg1s
left a comment
There was a problem hiding this comment.
All things considered, LGTM. I think the semantic changes are acceptable for 3.15 and we can see if we can improve the error reporting later.
| if (lz == NULL) { | ||
| return NULL; | ||
| } | ||
| PyLazyImportObject *child = (PyLazyImportObject *)lz; |
There was a problem hiding this comment.
| PyLazyImportObject *child = (PyLazyImportObject *)lz; | |
| PyLazyImportObject *child = PyLazyImportObject_CAST(lz); |
| _PyLazyImport_LoadChild(PyThreadState *tstate, PyObject *declaration, | ||
| PyObject *name) | ||
| { | ||
| PyLazyImportObject *source = (PyLazyImportObject *)declaration; |
There was a problem hiding this comment.
| PyLazyImportObject *source = (PyLazyImportObject *)declaration; | |
| assert(PyLazyImport_CheckExact(declaration)); | |
| PyLazyImportObject *source = PyLazyImportObject_CAST(declaration); |
Fixes #158140. With
lazy import pkg.afollowed bylazy import pkg.b, accessingpkg.acurrently importspkg.bfirst. Resolve ordinary dotted imports through the existing pending-child lookup, without publishing placeholders in package dictionaries. Custom namespace builtins and aliased parents retain their existing import behavior.The lazy-import, import, importlib, module, sys and C API suites pass in debug and free-threaded builds. Regression tests cover independent siblings, star imports, declaration cleanup, deleted attributes, import hooks and failed-import retries.
lazy import pkg.a) also imports a later importedpkg.b#158140